import random


def simulate_monty_hall(n):
    # 初始化计数器
    count_switch_wins = 0
    count_stay_wins = 0

    for _ in range(n):
        # 初始化奖品和玩家选择
        prize = random.randint(0, 2)  # 奖品的位置 0, 1, 2
        initial_choice = random.randint(0, 2)  # 玩家的初始选择

        # 确定其他两扇门
        other_doors = []
        for door in [0, 1, 2]:
            if door != initial_choice:
                other_doors.append(door)

        # 主持人打开一扇空门（随机选择）
        shown_door = random.choice(other_doors)

        # 确定剩下的那扇门（未被选择和未被打开的）
        final_door = None
        for door in [0, 1, 2]:
            if door != initial_choice and door != shown_door:
                final_door = door
                break

        # 玩家可以选择换门或不换
        # 不换门，直接检查初始选择
        if initial_choice == prize:
            count_stay_wins += 1

            # 换门，检查剩下的那扇门
        if final_door == prize:
            count_switch_wins += 1

            # 计算并返回结果，将概率转换为百分比形式
    return (count_switch_wins / n * 100), (count_stay_wins / n * 100)


n = 10000000
switch_win_rate, stay_win_rate = simulate_monty_hall(n)
print(f"换门赢得奖品的概率: {switch_win_rate}%")
print(f"不换门赢得奖品的概率: {stay_win_rate}%")